package com.estronger.shopmanage.ui.othertask.presenter;

import com.estronger.shopmanage.ui.othertask.bean.OtherTaskDetailBean;
import com.estronger.shopmanage.ui.othertask.fragment.detail.OtherTaskInfoFragment;
import com.google.gson.Gson;
import com.soonfor.evaluate.base.IEvalBasePresenter;
import com.soonfor.evaluate.http.api.Request;
import com.soonfor.evaluate.http.httptools.AsyncUtils;
import com.soonfor.evaluate.tools.ComToast;

/**
 * Created by DingYg on 2018-01-31.
 */

public class OtherTaskInfoPresenter implements IEvalBasePresenter, AsyncUtils.AsyncCallback {

    private OtherTaskInfoFragment bgFragment;

    public OtherTaskInfoPresenter(OtherTaskInfoFragment bgFragment) {
        this.bgFragment = bgFragment;
    }

    //获取任务详情
    public void getTaskDetail(String taskId) {
        Request.OtherTask.getOtherTaskDetailInfo(bgFragment.getContext(), taskId, Request.OtherTask.GET_OTHERTASK_DETAIL, this);
    }

    @Override
    public void success(int requestCode, String data) {
        bgFragment.closeLoadingDialog();
        try {
            switch (requestCode) {
                case Request.OtherTask.GET_OTHERTASK_DETAIL:
                    OtherTaskDetailBean tBean = new Gson().fromJson(data, OtherTaskDetailBean.class);
                    if (tBean != null) {
                        bgFragment.setViewByDetailInfo(tBean);
                    } else
                        ComToast.showFailToast(bgFragment.getContext(), "详情数据为空！");
                    break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void fail(int requestCode, int statusCode, String data, String msg) {
        if (bgFragment != null) {
            bgFragment.finishRefresh();
            bgFragment.closeLoadingDialog();
        }
    }
}
